package com.ay.shardingshere.controller;

import com.ay.shardingshere.entity.User;
import com.ay.shardingshere.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Random;

/**
 * @Author: ay
 * @Date: 2021/6/24
 * @Description:
 **/
@RestController
@RequestMapping("/user")
public class UserController {


    @Autowired
    private UserService userService;

    @PostMapping
    public void save(){
        for (int i = 0; i < 10; i++) {
            User user = new User();
            user.setSex('F');
            user.setUsername("zhangsan"+i);
            user.setAge(18);
            userService.save(user);
        }
    }


    /**
     * 用户信息列表查询
     * @return
     */
    public List<User> list(){
        List<User> list = userService.list();
        return list;
    }
}
